package com.sykj.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.sykj.bean.bis.BisShopCollect;
import com.sykj.bean.card.BisShopDto;
import com.sykj.mapper.GameLoadMapper;
import com.sykj.service.BisShopCollectService;
import com.sykj.util.reponse.CommonEnum;
import com.sykj.util.reponse.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @program: BeautyClub
 * @description:
 * @author: qiaoli
 * @create: 2020-08-10 09:43
 */
@RestController
@RequestMapping("/collect")
public class BisShopCollectController {
    @Autowired
    BisShopCollectService bisShopCollectService;

    @Autowired
    GameLoadMapper gameLoadMapper;
    @GetMapping("/sava/{customUserId}/{shopId}")
    public ResultBody  savaUserBycollect(@PathVariable("customUserId")String customUserId,@PathVariable("shopId")String shopId){
       QueryWrapper queryWrapper=new QueryWrapper();
       queryWrapper.eq("shop_id",shopId);
       queryWrapper.eq("custom_user_id",customUserId);

        BisShopCollect one = bisShopCollectService.getOne(queryWrapper);
          if(one == null){
              BisShopCollect bisShopCollect=new BisShopCollect();
              Timestamp timeStamp = new Timestamp(new Date().getTime());
              bisShopCollect.setCreateTime(timeStamp);
              bisShopCollect.setShopId(shopId);
              bisShopCollect.setCustomUserId(customUserId);


              boolean save = bisShopCollectService.save(bisShopCollect);
              if(save){
                  return new ResultBody(CommonEnum.BISSHOP_COLLECT_OK);
              }
              return  new ResultBody(CommonEnum.NOT_FOUND);
          }

          return  new ResultBody(CommonEnum.BISSHOP_COLLECT_ERROR);

    }
    @GetMapping("/delete/{collectId}")
    public ResultBody deleteByid(@PathVariable("collectId")String collectId){

        boolean b = bisShopCollectService.removeById(collectId);
         if(b){
             return new ResultBody(CommonEnum.SUCCESS);

         }
         return  new ResultBody((CommonEnum.WeChat_QUERY_ERROR));
    }

@GetMapping("/queryByid/{customUserId}")
    public ResultBody   QueryByid(@PathVariable("customUserId")String customUserId){
        List<BisShopDto> bisShopDtos = gameLoadMapper.queryShopByid(customUserId);
        return new ResultBody(CommonEnum.SUCCESS,bisShopDtos);
    }
}
